import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import AddEditModal from '#cpt/temp/AddEditModal'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import Delete from '#cpt/temp/Delete'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== private component
const Page = $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== data
const EnableData = [{name:'启用',value:'1'},{name:'待启用',value:'0'}]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 提交表单列表
		formData : [
			{ label: '视图名称',		name: 'dc_name', 	half:true,  required:true, },
			{ label: '视图代码',		name: 'dc_code', 	half:true, 	required:true },
			{ label: '排序',		name: 'sort', 		half:true, 	required:true, 	type:'number', value:0},
			{ label: '状态',		name: 'enabled', 	half:true, 	required:true, 	type:'select', data:EnableData },
			{ label: '视图描述',		name: 'dc_desc', 	full:true, required:true },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.fetch()
	}
	// paging
	fetch = () => $fn.fetch.call(this,'st-view/index')
	// 表单
		cols = [
			{ title: '视图名称', 	dataIndex: 'dc_name', 		width:150 },
			{ title: '视图代码', 	dataIndex: 'dc_name', 		width:200 },
			{ title: '视图描述', 	dataIndex: 'dc_desc', 		...$fn.table.status},
			{ title: '状态', 		dataIndex: 'enabled', 		width:220, render: text => {return +text === 1 ? '启用' : '待启用'}  },
			{ title: '排序', 		dataIndex: 'sort', 			width:220 },
			TableControls.controls.call(this, { width: 150})
	]
	// 表格操作按钮
	table_controls = (text,{ uuid }) => {
		return [
			TableControls.edit.call(this, 'st-view/info', { uuid }),				// 编辑
			this.onDel([uuid]),														// 删除
		]
	}
	// 操作按钮
	controls = () => {
		return [
			Controls.add.call(this),			// 添加
			this.onDel(),						// 删除
		]
	}
	// 删除
	onDel = uuid => Delete.call(this, 'st-view/del', { uuid, isKeys: !uuid })
	
	render(){
		return (
			<>
				<Page title='视图菜单管理' controls={this.controls()}>
					{/* 表格 */}
					{ Table.call(this) }
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ api: 'st-view/add', editApi:'st-view/edit' }) }
			</>
		)
	}
}

export default Index